home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / app / mainMenuEvents.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  16KB  |  453 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. import sys
  6. import actions
  7. from common import profile, pref, setpref
  8. from eventStack import AppEventHandlerMixin
  9. from gui.addcontactdialog import AddContactDialog
  10. from gui.buddylist.aboutdialog import AboutDialog
  11. from gui.filetransfer import FileTransferDialog
  12. from gui.imdialogs import ShowNewIMDialog
  13. from gui.model.menus import *
  14. from gui.native.helpers import createEmail
  15. import gui.pref.prefsdialog as prefsdialog
  16. import gui.protocols as gui
  17. from gui.visuallisteditor import VisualListEditor
  18. from util.diagnostic import do_diagnostic
  19.  
  20. def tracecall(fn):
  21.     if getattr(sys, 'testing', False):
  22.         
  23.         def trace(*args):
  24.             wx.GetApp().event_fired = fn
  25.             return fn(*args)
  26.  
  27.         return trace
  28.     else:
  29.         return fn
  30.  
  31. sorts = {
  32.     actions.SortByNone: 'none',
  33.     actions.SortByStatus: 'status',
  34.     actions.SortByName: 'name',
  35.     actions.SortByLogSize: 'log',
  36.     actions.SortByService: 'service' }
  37. hwndMap = { }
  38. menuTitles = { }
  39. buddylist_panel_names = dict(status = _('Status Panel'), blist = _('Buddy List'), elist = _('Email Accounts'), slist = _('Social Networks'), clist = _('Connections'))
  40.  
  41. class MainMenuEventHandler(AppEventHandlerMixin):
  42.     
  43.     def __init__(self):
  44.         AppEventHandlerMixin.__init__(self)
  45.  
  46.     
  47.     def register_handlers(self):
  48.         self.AddHandlerForID(actions.NewStatusMessage, self.new_status_message)
  49.         self.AddHandlerForID(actions.EditStatusMessage, self.edit_status_message)
  50.         self.AddHandlerForID(actions.MyAccounts, self.accounts)
  51.         self.AddHandlerForID(actions.NewIM, self.new_im)
  52.         self.AddHandlerForID(actions.AddContact, self.add_contact)
  53.         self.AddHandlerForID(actions.AddGroup, self.add_group)
  54.         self.AddHandlerForID(actions.RenameSelection, self.rename_selection)
  55.         self.AddHandlerForID(actions.DeleteSelection, self.delete_selection)
  56.         self.AddHandlerForID(actions.SignOff, self.sign_off)
  57.         self.AddHandlerForID(actions.AlwaysOnTop, self.always_on_top)
  58.         self.AddHandlerForID(actions.Skins, self.skins)
  59.         self.AddHandlerForID(actions.MenuBar, self.show_menubar)
  60.         self.AddHandlerForID(actions.StatusPanel, self.show_status_panel)
  61.         self.AddHandlerForID(actions.ArrangePanels, self.arrange_panels)
  62.         self.AddHandlerForID(actions.ShowMobileContacts, self.show_mobile_contacts)
  63.         self.AddHandlerForID(actions.ShowOfflineContacts, self.show_offline_contacts)
  64.         self.AddHandlerForID(actions.GroupOfflineContacts, self.group_offline_contacts)
  65.         self.AddHandlerForID(actions.HideOfflineGroups, self.hide_offline_groups)
  66.         self.AddHandlerForID(actions.SortByNone, self.sort_by)
  67.         self.AddHandlerForID(actions.SortByStatus, self.sort_by)
  68.         self.AddHandlerForID(actions.SortByName, self.sort_by)
  69.         self.AddHandlerForID(actions.SortByLogSize, self.sort_by)
  70.         self.AddHandlerForID(actions.SortByService, self.sort_by)
  71.         self.AddHandlerForID(actions.SortByAdvanced, self.sort_by)
  72.         self.AddHandlerForID(actions.Preferences, self.show_preferences)
  73.         self.AddHandlerForID(actions.FileTransferHistory, self.show_file_transfer_history)
  74.         self.AddHandlerForID(actions.ChatHistory, self.show_chat_history)
  75.         self.AddHandlerForID(actions.Documentation, self.show_documentation)
  76.         self.AddHandlerForID(actions.SupportForums, self.show_support_forums)
  77.         self.AddHandlerForID(actions.SubmitBugReport, self.submit_bug_report)
  78.         self.AddHandlerForID(actions.SuggestAFeature, self.suggest_a_feature)
  79.         self.AddHandlerForID(actions.ShowDebugConsole, self.show_debug_console)
  80.         self.AddHandlerForID(actions.RunTests, self.run_tests)
  81.         self.AddHandlerForID(actions.InviteYourFriends, self.invite_your_friends)
  82.         self.AddHandlerForID(actions.About, self.show_about)
  83.         self.Bind(wx.EVT_MENU_OPEN, self.update_menu)
  84.         if 'wxMSW' in wx.PlatformInfo:
  85.             parentFrame = self.get_buddy_list_frame()
  86.             parentFrame.BindWin32(WM_INITMENUPOPUP, self._initmenupopup)
  87.         
  88.  
  89.     if 'wxMSW' in wx.PlatformInfo:
  90.         
  91.         def _initmenupopup(self, hWnd, msg, wParam, lParam):
  92.             
  93.             try:
  94.                 menu = hwndMap[wParam]
  95.             except KeyError:
  96.                 buddylist = self.get_buddy_list_frame()
  97.                 if buddylist:
  98.                     menubar = buddylist.MenuBar
  99.                 
  100.                 for i in xrange(menubar.MenuCount):
  101.                     amenu = menubar.GetMenu(i)
  102.                     if amenu.HMenu not in hwndMap:
  103.                         hwndMap[amenu.HMenu] = amenu
  104.                     
  105.                     if amenu.HMenu == wParam:
  106.                         menu = amenu
  107.                         break
  108.                         continue
  109.                 
  110.  
  111.             if menu:
  112.                 evt = wx.PyCommandEvent(wx.EVT_MENU_OPEN, menu.Id)
  113.                 evt.Menu = menu
  114.                 menu.Handler.ProcessEvent(evt)
  115.             
  116.  
  117.     
  118.     
  119.     def fire_event_for_action(action, target = None):
  120.         if not target:
  121.             target = wx.GetApp()
  122.         
  123.         if target:
  124.             event = wx.CommandEvent(wx.EVT_COMMAND_MENU_SELECTED, action)
  125.             target.ProcessEvent(event)
  126.         
  127.  
  128.     
  129.     def get_buddy_list_frame(self):
  130.         buddylist = None
  131.         app = wx.GetApp()
  132.         if app:
  133.             buddylist = app.buddy_frame
  134.         
  135.         return buddylist
  136.  
  137.     
  138.     def get_buddy_list_panel(self):
  139.         buddylist = self.get_buddy_list_frame()
  140.         if buddylist:
  141.             return buddylist.buddyListPanel
  142.         else:
  143.             return None
  144.  
  145.     
  146.     def update_menu(self, event):
  147.         menu = event.GetMenu()
  148.         menubar = wx.GetApp().buddy_frame.MenuBar
  149.         if menubar:
  150.             title = None
  151.             if menu in menuTitles:
  152.                 title = menuTitles[menu]
  153.             else:
  154.                 for i in xrange(menubar.MenuCount):
  155.                     iter_menu = menubar.GetMenu(i)
  156.                     if iter_menu == menu:
  157.                         title = menuTitles[menu] = menubar.GetMenuLabel(i)
  158.                         continue
  159.                     for item in iter_menu.MenuItems:
  160.                         if item.IsSubMenu() and menu == item.SubMenu:
  161.                             title = menuTitles[menu] = item.GetItemLabel()
  162.                             continue
  163.                     
  164.                 
  165.             if title == _('&Digsby'):
  166.                 self.update_digsby_menu(menu)
  167.             elif title == _('&Sort By'):
  168.                 self.update_sort_menu(menu)
  169.             elif title == _('&View'):
  170.                 self.update_view_menu(menu)
  171.             
  172.         
  173.  
  174.     
  175.     def update_digsby_menu(self, menu):
  176.         buddylist = self.get_buddy_list_panel()
  177.         if buddylist:
  178.             b = buddylist.blist.SelectedItem
  179.             OfflineGroup = OfflineGroup
  180.             import contacts.buddylistfilters
  181.             allow_add = any((lambda .0: for x in .0:
  182. x.allow_contact_add)(profile.account_manager.connected_accounts))
  183.             menu.Enable(actions.NewIM, allow_add)
  184.             menu.Enable(actions.AddContact, allow_add)
  185.             menu.Enable(actions.AddGroup, allow_add)
  186.             renameitem = menu.FindItemById(actions.RenameSelection)
  187.             deleteitem = menu.FindItemById(actions.DeleteSelection)
  188.             if b is None and getattr(b, 'iswidget', False) or isinstance(b, OfflineGroup):
  189.                 renameitem.SetItemLabel(_('&Rename Selection'))
  190.                 deleteitem.SetItemLabel(_('&Delete Selection'))
  191.                 renameitem.Enable(False)
  192.                 deleteitem.Enable(False)
  193.             else:
  194.                 renameitem.SetItemLabel(_('&Rename %s') % getattr(b, 'alias', b.name))
  195.                 deleteitem.SetItemLabel(_('&Delete %s') % getattr(b, 'alias', b.name))
  196.                 renameitem.Enable(True)
  197.                 deleteitem.Enable(True)
  198.         
  199.  
  200.     
  201.     def update_sort_menu(self, menu):
  202.         checkedOne = False
  203.         sortby = pref('buddylist.sortby', 'none none')
  204.         for item in menu.MenuItems:
  205.             
  206.             try:
  207.                 if item.Id in sorts:
  208.                     sorttypes = sorts[item.Id] + ' none'
  209.                 else:
  210.                     sorttypes = object()
  211.             except IndexError:
  212.                 sorttypes = object()
  213.  
  214.             if item.Kind == wx.ITEM_CHECK:
  215.                 val = sorttypes == sortby
  216.                 item.Check(val)
  217.                 if val:
  218.                     checkedOne = True
  219.                 
  220.             val
  221.         
  222.         if not checkedOne:
  223.             list(menu.MenuItems)[-1].Check(True)
  224.         
  225.  
  226.     
  227.     def update_view_menu(self, menu):
  228.         sortstatus = pref('buddylist.sortby').startswith('*status')
  229.         showoff = pref('buddylist.show_offline')
  230.         showmob = pref('buddylist.show_mobile')
  231.         hidegroups = pref('buddylist.hide_offline_groups')
  232.         groupoff = pref('buddylist.group_offline')
  233.         showstat = pref('buddylist.show_status')
  234.         showmenu = pref('buddylist.show_menubar')
  235.         ontop = menu.FindItemById(actions.AlwaysOnTop)
  236.         showmobile = menu.FindItemById(actions.ShowMobileContacts)
  237.         showoffline = menu.FindItemById(actions.ShowOfflineContacts)
  238.         groupoffline = menu.FindItemById(actions.GroupOfflineContacts)
  239.         hideoffline = menu.FindItemById(actions.HideOfflineGroups)
  240.         statuspanel = menu.FindItemById(actions.StatusPanel)
  241.         menubar = menu.FindItemById(actions.MenuBar)
  242.         showmobile.Check(showmob)
  243.         showoffline.Check(showoff)
  244.         statuspanel.Check(showstat)
  245.         if menubar:
  246.             menubar.Check(showmenu)
  247.         
  248.         buddy_frame = self.get_buddy_list_frame()
  249.         if buddy_frame:
  250.             ontop.Check(buddy_frame.HasFlag(wx.STAY_ON_TOP))
  251.         
  252.         if not sortstatus:
  253.             pass
  254.         groupoffline.Enable(showoff)
  255.         if groupoff and not sortstatus:
  256.             pass
  257.         groupoffline.Check(showoff)
  258.         hideoffline.Enable(not sortstatus)
  259.         if (sortstatus or not showoff) and not sortstatus:
  260.             pass
  261.         hideoffline.Check(hidegroups)
  262.  
  263.     
  264.     def new_status_message(self, event = None):
  265.         new_custom_status = new_custom_status
  266.         import gui.status
  267.         new_custom_status(None, save_checkbox = True)
  268.  
  269.     new_status_message = tracecall(new_status_message)
  270.     
  271.     def edit_status_message(self, event = None):
  272.         prefsdialog.show('status')
  273.  
  274.     edit_status_message = tracecall(edit_status_message)
  275.     
  276.     def accounts(self, event = None):
  277.         prefsdialog.show('accounts')
  278.  
  279.     accounts = tracecall(accounts)
  280.     
  281.     def update_bool_pref(self, pref):
  282.         profile.prefs[pref] = not profile.prefs[pref]
  283.  
  284.     update_bool_pref = tracecall(update_bool_pref)
  285.     
  286.     def update_check_pref(self, item, value):
  287.         item.Check(value)
  288.  
  289.     
  290.     def new_im(self, event = None):
  291.         ShowNewIMDialog()
  292.  
  293.     new_im = tracecall(new_im)
  294.     
  295.     def add_contact(self, event = None):
  296.         AddContactDialog.MakeOrShow()
  297.  
  298.     add_contact = tracecall(add_contact)
  299.     
  300.     def add_group(self, event = None):
  301.         gui.protocols.add_group()
  302.  
  303.     add_group = tracecall(add_group)
  304.     
  305.     def rename_selection(self, event = None):
  306.         buddylist = self.get_buddy_list_panel()
  307.         if buddylist:
  308.             buddylist.blist.rename_selected()
  309.         
  310.  
  311.     rename_selection = tracecall(rename_selection)
  312.     
  313.     def delete_selection(self, event = None):
  314.         buddylist = self.get_buddy_list_panel()
  315.         if buddylist:
  316.             buddylist.blist.delete_blist_item(buddylist.blist.SelectedItem)
  317.         
  318.  
  319.     delete_selection = tracecall(delete_selection)
  320.     
  321.     def sign_off(self, event = None):
  322.         profile.signoff()
  323.  
  324.     sign_off = tracecall(sign_off)
  325.     
  326.     def always_on_top(self, event = None):
  327.         self.update_bool_pref('buddylist.always_on_top')
  328.  
  329.     always_on_top = tracecall(always_on_top)
  330.     
  331.     def skins(self, event = None):
  332.         prefsdialog.show('appearance')
  333.  
  334.     skins = tracecall(skins)
  335.     
  336.     def show_menubar(self, event = None):
  337.         pref = 'buddylist.show_menubar'
  338.         self.update_bool_pref(pref)
  339.         if not profile.prefs[pref]:
  340.             wx.MessageBox(_('You can bring back the menubar by right clicking on the digsby icon in the task tray.'), _('Hide Menu Bar'))
  341.         
  342.  
  343.     show_menubar = tracecall(show_menubar)
  344.     
  345.     def show_status_panel(self, event = None):
  346.         self.update_bool_pref('buddylist.show_status')
  347.  
  348.     show_status_panel = tracecall(show_status_panel)
  349.     
  350.     def arrange_panels(self, event = None):
  351.         if VisualListEditor.RaiseExisting():
  352.             return None
  353.         
  354.         buddylist = self.get_buddy_list_panel()
  355.         editor = VisualListEditor(buddylist, profile.prefs['buddylist.order'], buddylist_panel_names, (lambda l: setpref('buddylist.order', l)), _('Arrange Panels'))
  356.         editor.Show()
  357.  
  358.     arrange_panels = tracecall(arrange_panels)
  359.     
  360.     def show_mobile_contacts(self, event = None):
  361.         self.update_bool_pref('buddylist.show_mobile')
  362.  
  363.     show_mobile_contacts = tracecall(show_mobile_contacts)
  364.     
  365.     def show_offline_contacts(self, event = None):
  366.         self.update_bool_pref('buddylist.show_offline')
  367.  
  368.     show_offline_contacts = tracecall(show_offline_contacts)
  369.     
  370.     def group_offline_contacts(self, event = None):
  371.         self.update_bool_pref('buddylist.group_offline')
  372.  
  373.     group_offline_contacts = tracecall(group_offline_contacts)
  374.     
  375.     def hide_offline_groups(self, event = None):
  376.         self.update_bool_pref('buddylist.hide_offline_groups')
  377.  
  378.     hide_offline_groups = tracecall(hide_offline_groups)
  379.     
  380.     def sort_by(self, event):
  381.         if event.GetId() in sorts:
  382.             setpref('buddylist.sortby', sorts[event.GetId()] + ' none')
  383.         else:
  384.             prefsdialog.show('contact_list')
  385.  
  386.     sort_by = tracecall(sort_by)
  387.     
  388.     def show_preferences(self, event = None):
  389.         prefsdialog.show('accounts')
  390.  
  391.     show_preferences = tracecall(show_preferences)
  392.     
  393.     def show_file_transfer_history(self, event = None):
  394.         FileTransferDialog.Display()
  395.  
  396.     show_file_transfer_history = tracecall(show_file_transfer_history)
  397.     
  398.     def show_chat_history(self, event = None):
  399.         PastBrowser = PastBrowser
  400.         import gui.pastbrowser
  401.         PastBrowser.MakeOrShow()
  402.  
  403.     show_chat_history = tracecall(show_chat_history)
  404.     
  405.     def show_documentation(self, event = None):
  406.         wx.LaunchDefaultBrowser('http://wiki.digsby.com')
  407.  
  408.     show_documentation = tracecall(show_documentation)
  409.     
  410.     def show_support_forums(self, event = None):
  411.         wx.LaunchDefaultBrowser('http://forum.digsby.com')
  412.  
  413.     show_support_forums = tracecall(show_support_forums)
  414.     
  415.     def submit_bug_report(self, event = None):
  416.         do_diagnostic()
  417.  
  418.     submit_bug_report = tracecall(submit_bug_report)
  419.     
  420.     def suggest_a_feature(self, event = None):
  421.         createEmail('mailto:features@digsby.com')
  422.  
  423.     suggest_a_feature = tracecall(suggest_a_feature)
  424.     
  425.     def show_debug_console(self, event = None):
  426.         wx.GetApp().toggle_crust()
  427.  
  428.     show_debug_console = tracecall(show_debug_console)
  429.     
  430.     def invite_your_friends(self, event = None):
  431.         wx.LaunchDefaultBrowser('http://www.digsby.com/invite')
  432.  
  433.     invite_your_friends = tracecall(invite_your_friends)
  434.     
  435.     def show_about(self, event = None):
  436.         diag = AboutDialog()
  437.         
  438.         try:
  439.             diag.ShowModal()
  440.         finally:
  441.             diag.Close()
  442.  
  443.  
  444.     show_about = tracecall(show_about)
  445.     
  446.     def run_tests(self, event = None):
  447.         import tests.unittests as test
  448.         testDialog = test.UnitTestDialog(None, -1, size = (400, 400))
  449.         testDialog.Show()
  450.  
  451.     run_tests = tracecall(run_tests)
  452.  
  453.